#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__autho__ = "Tony.Don"
__lastupdatetime__ = "2017/09/20"
import os
import threading
import re
import application.webanalysis
import time,datetime
import hashlib
from core.Spider import myhttp
from core.parser import parserHtml
from core.rule import rule
from os.path import os
from models.domain import domain

'''
class\r\n
    rule.gzw.gzw(rule)\r\n
description\r\n
    分析规则(html分析法)\r\n
'''
class geturl(rule):

    __filename__=None
    __tpath__=None
    def __init__(self,domain):
        self._domain=domain
    def getRule(self,content):
        re_domain=re.compile('(http|https)://([\w]+\.)+.([\w]+)',re.I)
        domainName=re_domain.finditer(content)
        if domainName:
            domainList=dict()
            for item in domainName:
                domainList[item.group(0)]=item.group(0)
            for item in domainList:
                result=domain()
                result.domainName=item
                result.lastGetTime=datetime.datetime.utcnow()+datetime.timedelta(days=-1)
                result.hashMD5=result.domainName
                if not result.findOne({'name':result.domainName}):
                    result.toSave()
                    print("save domain %s" % (item))
        else:
            pass

    def callback(self,args):
        pass